<?php
require_once 'include/config.inc.php';
require_once('Mail.php');

$file = $amtu_folder . "processingreports/PROCESSING1710521788.txt";

function csv_to_array($filename='', $delimiter="\t") {
        if(!file_exists($filename) || !is_readable($filename))
                return FALSE;

        $header = NULL;
        $data = array();
        $counter=0;
        if (($handle = fopen($filename, 'r')) !== FALSE) {
                for($i=0;$i<4;$i++)
                        fgets($handle);
                $header = fgetcsv($handle, 1000, $delimiter);
                while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE){
                        $data[] = array_combine($header, $row);}
                fclose($handle);
        }
        return $data;
}

//print_r(csv_to_array($file));


foreach(csv_to_array($file) as $element){
	switch($element['error-code']) {
		//case 8004:
        //      echo $element['sku'] . "\n";
        //case 8041:
        //      exit(2);
		case 20009: # image wrong size
			echo $element['sku'] . "\n";
				$mail_message = $mail_message . "der Artikel mit der sku: " .  $element['sku'] . " enthaelt ein Produktbild mit zu kleinen Abmessungen \n";
		//default:
        //      exit(1);
        }
}

$mailer = Mail::factory('smtp',$mail_options);
if (true === PEAR::isError($mailer)) {
        die ($mailer->getMessage());
        }
$mail_res = $mailer->send($mail_receipient,$mail_headers,$mail_message);
if (true === PEAR::isError($mail_res)) {
        die ($mail_res->getMessage());
        }
?>